use tauri::State;

use crate::{models::download::DownloadTaskResponse, utils::download_manager::DownloadManager};

#[tauri::command]
pub async fn get_downloads(
    manager: State<'_, DownloadManager>,
) -> Result<Vec<DownloadTaskResponse>, String> {
    manager.get_downloads().await
}

#[tauri::command]
pub async fn add_download(
    category: String,
    pkgname: String,
    filename: String,
    name: String,
    manager: State<'_, DownloadManager>,
) -> Result<(), String> {
    manager
        .add_download(category, pkgname, filename, name)
        .await
}

#[tauri::command]
pub async fn pause_download(
    category: String,
    pkgname: String,
    manager: State<'_, DownloadManager>,
) -> Result<(), String> {
    manager.pause_download(category, pkgname).await
}

#[tauri::command]
pub async fn resume_download(
    category: String,
    pkgname: String,
    manager: State<'_, DownloadManager>,
) -> Result<(), String> {
    manager.resume_download(category, pkgname).await
}

#[tauri::command]
pub async fn cancel_download(
    category: String,
    pkgname: String,
    manager: State<'_, DownloadManager>,
) -> Result<(), String> {
    manager.cancel_download(category, pkgname).await
}
